<?php
if(!function_exists('category_navbar_active')){
    function category_navbar_active($category_id){
        return active_class(if_route('categories.show') && if_route_param('category',$category_id));
    }
}

if(!function_exists('make_desc')){
    function make_desc($value,$len=200){
        $desc = trim(preg_replace('/\r\n|\r|\n+/',' ',strip_tags($value)));
        return str()->limit($desc,$len);
    }
}

function model_plural_name($model){
    //App\Models\User
    $full_model_name = get_class($model);
    $class_name = class_basename($full_model_name);
    $snake_class_name = str()->snake($class_name);
    return str()->plural($snake_class_name);
}

function model_link($title,$model,$prefix=''){
    $model_name = model_plural_name($model);
    $prefix = $prefix ? "/$prefix/" : '/';
    $url = config('app.url').$prefix.$model_name.'/'.$model->id;
    return '<a href="'.$url.'">'.$title.'</a>';
}
function model_admin_link($title,$model){
    return model_link($title,$model,'admin');
}


